package com.zsrt.java.day20161229.zsh.demo01;

import java.util.Scanner;

public class CalculatorGame {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		
		do{
			System.out.println("请输入用户名：");
			String name=sc.next();
			System.out.println("请输入密码：");
			String password=sc.next();
			
			if(name.equals(password)){
				System.out.println("密码正确，game start!");
				break;
			}else{
				System.out.println("密码错误，请重新输入！（提示：用户名=密码）");
			}
		}while(true);
		
outer:	while(true){
			System.out.println("请输入一个3位数整数（范围：100~999）：");
			int number=sc.nextInt();
			while(true){
				if(100<=number&&number<=999){
					break;	
				}else{
					System.out.println("输入有误，请重新按要求输入！（输入整数范围：100~999）");
					System.out.println("请输入一个3位数整数（范围：100~999）：");
					int number1=sc.nextInt();
					if(100<=number1&&number1<=999){
						number=number1;
						break;	
					}else{
						System.out.println("输入异常，强制退出游戏！请重新运行游戏");
						break outer;
					}
				}
			}
			
			int i=number%10%4;
			
			switch(i){
				case 0:add(number);break;
				case 1:sub(number);break;
				case 2:mul(number);break;
				case 3:div(number);break;
			}
			
			System.out.println("game over,are you sure to play again? y / n");
			String exit=sc.next();
			if(exit.equals("y")|exit.equals("Y")){
				continue;
			}else if(exit.equals("n")|exit.equals("N")){
				System.out.println("退出！");
				break;
			}
		}
		sc.close();
	}

	public static void add(int num){
		int gw=num%10;
		int sw=num/10%10;
		int bw=num/100;
		int sum=gw+sw+bw;
		System.out.println("输入的整数是："+num);
		System.out.println("计算结果为："+gw+"+"+sw+"+"+bw+"="+sum);
	}
	
	public static void sub(int num){
		int gw=num%10;
		int sw=num/10%10;
		int bw=num/100;
		int sum=gw-sw-bw;
		System.out.println("输入的整数是："+num);
		System.out.println("计算结果为："+gw+"-"+sw+"-"+bw+"="+sum);
	}
	
	public static void mul(int num){
		int gw=num%10;
		int sw=num/10%10;
		int bw=num/100;
		int sum=gw*sw*bw;
		System.out.println("输入的整数是："+num);
		System.out.println("计算结果为："+gw+"*"+sw+"*"+bw+"="+sum);
	}
	
	public static void div(int num){
		int gw=num%10;
		int sw=num/10%10;
		int bw=num/100;
		int sum=gw/sw/bw;
		System.out.println("输入的整数是："+num);
		System.out.println("计算结果为："+gw+"/"+sw+"/"+bw+"="+sum);
	}
	
}
